<?php

namespace App\Services\Game\Setting;

use App\Services\Service;
use App\Services\Traits\DatabaseMysql;
use App\Models\Game\Config\Game;

class GameService extends Service
{
    use DatabaseMysql;

    /**
     * 获取数据列表
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Database\Eloquent\Collection[]|int[]
     */
    public function getList($request)
    {
        $query = Game::query();

        // 软删除筛选
        $this->makeWhereDeleted($request, $query);
        // 游戏等级
        $this->makeWhereParam($request, 'grade', $query);
        // 游戏分类
        $this->makeWhereParamBits($request, 'category', $query);

        // 数据条数
        $total = (clone $query)->count();
        // 数据分页
        $this->makePaginationParam($request, $query);
        // 查询数据
        $collection = $query
            ->orderBy('index', 'desc')
            ->orderBy('id', 'desc')
            ->get();

        return [
            $collection,
            $total
        ];
    }
}
